package com.movie.ticket.sale.movieassembly.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.movie.ticket.sale.MovieDetailsInterface;
import com.movie.ticket.sale.form.OrderSeat;
import com.movie.ticket.sale.movieassembly.common.MapToStringUtil;
import com.movie.ticket.sale.movieassembly.common.MovieAuthor;
import com.movie.ticket.sale.movieassembly.common.MovieTicket;
import com.movie.ticket.sale.movieassembly.common.Resolver;
import com.movie.ticket.sale.movieassembly.controller.form.*;
import com.movie.ticket.sale.movieassembly.controller.form.TMovie;
import com.movie.ticket.sale.movieassembly.service.MovieDetailsService;
import com.movie.ticket.sale.moviecommon.common.Result;
import com.movie.ticket.sale.moviecommon.model.*;
//import com.movie.ticket.sale.moviecommon.model.TMovie;

import com.netflix.client.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class MovieDetailsControlle implements MovieDetailsInterface {
    @Autowired
    private MovieDetailsService movieDetailsService;
    @Autowired
    private MovieTicket movieTicket;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private OrderMessageRepo orderMessageRepo;
    @Autowired
    private MovieAuthor movieAuthor;
    @Autowired
    private RedissonClient redissonClient;

    /**
     * 展示电影封面
     */
    public Result getMovieData(int id) {
        log.info("(封面)电影名称参数为：{}", id);
        String filePath = movieDetailsService.getMovieData(id);
        return Result.success(filePath);
    }

    /**
     * 展示电影信息(包括简介)
     */
    public Result getMovieInnformention(int id) {
        log.info("(信息)电影名称参数为：{}", id);
        TMovie tMovie = movieDetailsService.getMovieInnformention(id);
//        BoundHashOperations boundListOperations = redisTemplate.boundHashOps("TMovie_"+id+"_"+System.currentTimeMillis());
//
//        boundListOperations.put();
        return Result.success(tMovie);
    }

    /**
     * 展示电影评论
     *
     * @param id
     * @param currPage
     * @param number
     * @return
     */
    public Result getMovieReview(@RequestParam(value = "id") int id, @RequestParam(value = "currPage", defaultValue = "1") int currPage, @RequestParam(value = "number", defaultValue = "5") int number) {
        log.info("(评论分页展示)电影名称参数为：{}{}{}", id, currPage, number);
//        int currPage1=(currPage-1)*number;
//        //查询总量
//        int commentNumber=movieDetailsService.getMovieReviewNumber(id);
//        System.out.println("总量为："+commentNumber);
//        //查询数据
//        List<TComment> list=movieDetailsService.getMovieReview(id,currPage1,number);
//        System.out.println(list);
//        //总页数
//        int size = commentNumber % number ==0 ?commentNumber/number:commentNumber/number+1;
//        System.out.println("总页数："+size);
//        //创建一个page对象
//        MoviePage moviePage = new MoviePage(currPage,commentNumber,size);
//        //创建一个result对象
//        MovieLimit movieLimit=new MovieLimit();
//        movieLimit.setList(list);
//        movieLimit.setObj(moviePage);
        Page<MovieCommon> page = new Page<>();
        page.setCurrent(currPage);
        page.setSize(number);
        IPage<MovieCommon> getMovieReview = movieDetailsService.getMovieReview(page, id);
        return Result.success(getMovieReview);
    }

    /**
     * 展示电影导演
     *
     * @param id
     * @return
     */
    public Result getMoviePerson(int id) {
        log.info("(演职人员)电影名称参数为：{}", id);
        //导演的对象
        List<MoviePerson> list = movieDetailsService.getMoviePersonDirector(id);
        return Result.success(list);
    }

    /**
     * 展示演员
     *
     * @param id
     * @return
     */
    public Result getMoviePersonAactor(int id) {
        log.info("(演职人员)电影名称参数为：{}", id);
        //演员
        List<MoviePerson> list = movieDetailsService.getMoviePersonActor(id);
        return Result.success(list);
    }

    /**
     * 展示电影剧照
     *
     * @param id
     * @return
     */
    public Result getMoviePhoto(int id) {
        log.info("(剧照)电影名称参数为：{}", id);
        List<String> list = movieDetailsService.getMoviePhoto(id);
        return Result.success(list);
    }

    /**
     * 演员人员头像
     *
     * @param id
     * @return
     */
    public Result getCastPhotoAuctor(int id) {
        log.info("展示演员人员头像演员参数名字：{}", id);
        List<String> actors = movieDetailsService.getAllActorByMovieId(id);
        //List<String> photoAuctor=movieDetailsService.getCastPhotoAuctor(id);
        List<MoviePerson> li = new ArrayList<>();
        System.out.println(actors);
        for (String name : actors) {
            List<String> list = movieDetailsService.getAllPhotoActorsByName(name);
            MoviePerson moviePerson = new MoviePerson();
            moviePerson.setName(name);
            moviePerson.setHeadPicture(list);
            li.add(moviePerson);
        }
        return Result.success(li);
    }

    /**
     * 展示导演头像
     *
     * @param id
     * @return
     */
    public Result getCastPhotoDirector(int id) {
        log.info("展示演员人员头像演员参数名字：{}", id);
        //String photoAuctor=movieDetailsService.getCastPhotoDirector(id);
        List<String> actors = movieDetailsService.getAllDirectorByMovieId(id);
        List<MoviePerson> li = new ArrayList<>();
        System.out.println(actors);
        for (String name : actors) {
            List<String> list = movieDetailsService.getAllPhotoDirectorByName(name);
            MoviePerson moviePerson = new MoviePerson();
            moviePerson.setName(name);
            moviePerson.setHeadPicture(list);
            li.add(moviePerson);
        }
        return Result.success(li);
    }

    /**
     * 演职人员参演作品
     *
     * @param id
     * @param type
     * @return
     */
    public Result getCastInWork(@RequestParam(value = "id") int id, @RequestParam(value = "type") int type) {
        log.info("展示演员参演作品参数：{}{}", id, type);

        return Result.success("返回演员对应的作品对象");
    }

    /**
     * 选择影院，按照区域，时间，影厅，服务筛选，传入经纬度默认距离最近的在前面，可调整为通过价格排序
     *
     * @param cinemaName
     * @param region
     * @param
     * @param
     * @param service
     * @param currPage
     * @param number
     * @return
     */
    public Result chooseCinema(@RequestParam(value = "cinemaName") String cinemaName, @RequestParam(value = "region") String region, @RequestParam(value = "service") String service, @RequestParam(value = "currPage", defaultValue = "1") int currPage, @RequestParam(value = "number", defaultValue = "5") int number) {
        log.info("筛选影院参数：影院名{}区域{}服务类型{}起始页{},每页展示数量{}", cinemaName, region, service, currPage, number);
        //List<CinemaMessage>list=movieDetailsService.chooseCinema(cinemaName,region,showTime,auditoriumType,service,currPage,number);
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间" + simpleDateFormat.format(date));
        Page<CinemaMessage> page = new Page<>();
        page.setCurrent(currPage);
        page.setSize(number);
        IPage<CinemaMessage> cinemaMessageIPage = movieDetailsService.getCinemaMessage(page, cinemaName, region, simpleDateFormat.format(date), service);
        return Result.success(cinemaMessageIPage);
    }

    /**
     * 影院详情包含影院照片，影院信息，地址信息（地图）
     *
     * @param id
     * @return
     */
    public Result getCinemaMessagePicture(int id) {
        log.info("展示信息所需影院名字：{}", id);
        //获取影院信息
        CinemaInformention cinemaInformention = movieDetailsService.getCinemaMessagePicture(id);

        return Result.success(cinemaInformention);
    }

    /**
     * 展示当前影院上线的电影
     *
     * @param id
     * @return
     */
    public Result getCinemaMovie(@RequestParam(value = "id") int id) {
        log.info("展示信息所需影院名字：{}{}", id);
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间" + simpleDateFormat.format(date));
        //获取当前影院热映的影片
        List<MovieInformention> movieInformention = movieDetailsService.getCinemaMovie(id, simpleDateFormat.format(date));
        System.out.println(movieInformention);
        return Result.success(movieInformention);
    }
//************************************进入选座界面*************************************************

    /**
     * 获取场次的可用座位信息
     */
    public Result getSetsByPerid(int peridId) {
        if (peridId <= 0)
            return Result.fail(426, "非法场次id");

        String sests = movieDetailsService.getSetsByPerid(peridId);
        if (sests == null || sests.length() == 0)
            return Result.fail(426, "影厅无座位信息");

        Map<String, String> newSets = new HashMap<>();
        Map<String, String> map1 = (Map<String, String>) JSON.parse(sests);
        for (String str : map1.keySet()) {
            //检查数据库座位是否被占用
            int state = Integer.parseInt(map1.get(str));
            if (state == 0)
                newSets.put(str, state + "");
        }
        return Result.success(newSets);
    }

    // TODO: 2020/12/3 获取用户所选择的座位信息
//    static double totleMoney;
//    static int perId;
//    static int auditoriumId;
//    static String userTel;
//    static int id;
//    static double ticketPrice;
//    static int num;//票数
//    static String tradeNuo;//订单号
//    static double tip;//手续费
//    static String[] list;//座位
    /**
     * 获取用户所选择的座位信息,需传入用户手机号，座位信息，场次id，优惠券id
     *
     * @param orderSeat
     * @return
     */
    RLock rLock = null;

    public Result addSeat(@RequestBody OrderSeat orderSeat) {
        log.info("传入的座位信息为：{}", orderSeat);
        HashOperations hashOperations = redisTemplate.opsForHash();
        HashMap<String, Object> map = new HashMap<>();

        //获取场次座位
        Map<String, String> map2 = (Map<String, String>) getSetsByPerid(orderSeat.getPerId()).getData();
        String sets = orderSeat.getList();
        String[] list2 = sets.split(",");
        int i = 0;
        for (String s : list2) {
            i = 0;
            for (String str : map2.keySet()) {
                i++;
                if (s.equals(str)) {
                    log.info("{},座位可用", s);
                    break;
                } else if (i == map2.size())
                    return Result.fail(426, "错误选座");
            }
        }

        int perId = orderSeat.getPerId();
        //根据场次id获取电影id，影厅id，
        OrderMessage orderMsg = movieDetailsService.getMovieIdByPerId(perId);
        System.out.println("orderMsg:" + orderMsg);
        //获取电话
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String userTel = request.getHeader("tel");
        System.out.println("userTel：" + userTel);
        int userId = movieDetailsService.getUserIdByUserTel(userTel);
        System.out.println("userId:" + userId);
        System.out.println("orderMsg.getCinemaId():" + orderMsg.getCinemaId());
        int id = orderSeat.getId();
        //查询出该场次的信息
        TPerid tPerid = movieDetailsService.selectTperidById(orderSeat.getPerId());
        System.out.println(tPerid);
        int auditoriumId = tPerid.getAuditoriumId();
        //下的订单数
        //number=orderSeat.getList();
        String list1 = orderSeat.getList();
        String[] list = list1.split(",");

        for (int index = 0; index < list.length; index++) {
            rLock = redissonClient.getLock(perId + list[index]);
        }
        int num = 0;
        for (String seat : list) {
            System.out.println(seat);
            num++;
        }
        System.out.println("票数：" + num);
        //查询是否存在该优惠券
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间" + simpleDateFormat.format(date));
        TDiscount tDiscount = movieDetailsService.getDiscountById(orderSeat.getId(), simpleDateFormat.format(date));
        System.out.println("tDiscount:" + tDiscount);
        //查询是否是会员
        TVip tVip = movieDetailsService.getTvip(userId, orderMsg.getCinemaId(), simpleDateFormat.format(date));
        System.out.println("会员信息：" + tVip);
        //计算应该支付的金额
        double ticketPrice = num * tPerid.getPrice();
        //计算手续费
        double tip = ticketPrice * 0.08;
        //根据是否使用优惠券
        double totleMoney;
        if (tDiscount != null) {
            //根据查询出的会员信息进行运算
            if (tVip != null) {
                totleMoney = (num * tPerid.getPrice()) * tVip.getTicketDiscount() + tip * tVip.getTipDiscount() - tDiscount.getAmount();
                tip = tip * tVip.getTipDiscount();
                System.out.println("有优惠券，是会员");
            } else {
                totleMoney = num * tPerid.getPrice() - tDiscount.getAmount() + tip;
                System.out.println("有优惠券，不是会员");
            }
        } else {
            //根据查询出的会员信息进行运算
            if (tVip != null) {
                totleMoney = (num * tPerid.getPrice()) * tVip.getTicketDiscount() + tip * tVip.getTipDiscount();
                tip = tip * tVip.getTipDiscount();
                System.out.println("没优惠券，是会员");
            } else {
                totleMoney = num * tPerid.getPrice() + tip;
                System.out.println("没优惠券，不是会员");
            }
        }
        System.out.println("totleMoney" + totleMoney);
        //对订单金额取整
        totleMoney = Math.round(totleMoney * 100) / 100.0;
        System.out.println("订单金额*************************************" + totleMoney);
        //生成核对码
        String checkCode = (int) ((Math.random() * 9000) + 1000) + "";
        System.out.println("****************************************************************************************************.\n");
        map.put("totleMoney", (totleMoney + ""));
        map.put("perId", (perId + ""));
        map.put("auditoriumId", (auditoriumId + ""));
        map.put("userTel", userTel);
        map.put("id", (id + ""));
        map.put("ticketPrice", (ticketPrice + ""));
        map.put("num", (num + ""));
        map.put("tip", (tip + ""));
        map.put("list1", list1);
        map.put("checkCode", (checkCode + ""));
        hashOperations.putAll("orderMessage_" + userTel, map);


        BoundHashOperations boundListOperations = redisTemplate.boundHashOps("orderMessage_" + userTel);
        System.out.println("redis查询出来的tel:" + boundListOperations.get("totleMoney"));
        //调用短信接口
        Result rel = movieAuthor.getTelCode(userTel);
        if (rel.isSuccess()) {
            return Result.success(rel + "应支付金额：" + totleMoney);
        }

        return Result.fail(426, "重复下单");
    }

    /**
     * 发送验证码（验证）传入验证码
     */
//    static int userId;
    public Result checkMessage(String verificationCode) {
        log.info("验证短信验证码：{}", verificationCode);
        //获取电话
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String userTel1 = request.getHeader("tel");
        System.out.println("****************************************************************");
        BoundHashOperations boundListOperations = redisTemplate.boundHashOps("orderMessage_" + userTel1);
        boundListOperations.expire(15, TimeUnit.MINUTES);
        System.out.println(boundListOperations);
        double totleMoney = Double.parseDouble((String) boundListOperations.get("totleMoney"));
        System.out.println(totleMoney);
        int perId = Integer.parseInt((String) boundListOperations.get("perId"));
        System.out.println(perId);
        int auditoriumId = Integer.parseInt((String) boundListOperations.get("auditoriumId"));
        System.out.println(auditoriumId);
        String userTel = (String) boundListOperations.get("userTel");
        System.out.println(userTel);
        int id = Integer.parseInt((String) boundListOperations.get("id"));
        System.out.println(id);
        double ticketPrice = Double.parseDouble((String) boundListOperations.get("ticketPrice"));
        System.out.println(ticketPrice);
        int num = Integer.parseInt((String) boundListOperations.get("num"));
        System.out.println(num);
        String list1 = (String) boundListOperations.get("list1");
        System.out.println(list1);
        String[] list = list1.split(",");
        String checkCode = (String) boundListOperations.get("checkCode");

        HashOperations hashOperations = redisTemplate.opsForHash();
        //Result result=(userTel,verificationCode);
        Result result = movieAuthor.checkTelCode(userTel, verificationCode);
        if (result.isSuccess()) {
            //添加订单
            //获取用户id
            int userId = movieDetailsService.getUserIdByUserTel(userTel);

            //根据场次id获取电影id，影厅id，
            OrderMessage orderMsg = movieDetailsService.getMovieIdByPerId(perId);
            //计算手续费
            double tip = ticketPrice * 0.08;
            //当前时间
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = simpleDateFormat.format(date);
            //生成订单号
            String tradeNuo1 = "TOrderMovie_" + userId + "_" + System.currentTimeMillis();
            //添加座位信息进入座位信息表
            OrderMessage orderMessage = new OrderMessage();
            orderMessage.setTradeNuo(tradeNuo1);
            orderMessage.setUserId(userId);
            orderMessage.setCheckCode(checkCode);
            orderMessage.setCinemaId(orderMsg.getCinemaId());
            orderMessage.setMovieId(orderMsg.getMovieId());
            orderMessage.setAuditoriumId(auditoriumId);
            orderMessage.setPeridId(perId);
            orderMessage.setRealPrice(totleMoney);
            orderMessage.setTicketPrice(ticketPrice);
            orderMessage.setTip(tip);
            orderMessage.setNumber(num);
            orderMessage.setRefund(0);
            orderMessage.setChange(0);
            orderMessage.setDiscountId(id);
            orderMessage.setData(format);
            orderMessage.setState(0);
            orderMessage.setStatus(0);
            orderMessage.setStatu(0);
            System.out.println("添加进入的******************************************orderMessage对象:" + orderMessage);
            movieDetailsService.addOrderMessage(orderMessage);

            //修改trade_nuo字段
            String tradeNuo = "TOrderMovie_" + orderMessage.getId() + "_" + System.currentTimeMillis() + "_" + userTel;
            movieDetailsService.updateTradeNuo(tradeNuo, orderMessage.getId());
            String out_trade_no = "waiceng";

            //修改优惠券状态
            movieDetailsService.changeDiscountState(id);
//            BoundHashOperations boundListOperations = redisTemplate.boundHashOps(out_trade_no);
//            boundListOperations.put(out_trade_no,orderMessage);
            //RedisHandler redisHandler=new RedisHand
            HashMap<String, String> map = new HashMap<>();
            map.put("tradeNuo", tradeNuo);
            int i = 1;
            for (String seat : list) {
                movieDetailsService.addOrderTicket(orderMessage.getId(), seat, format);
                map.put("seat" + i, seat);
                i++;
            }
            //修改t_perid的seat_stream为虚占位状态
            String seats = movieDetailsService.getSetsByPerid(perId);
            Map<String, String> map1 = (Map<String, String>) JSON.parse(seats);
            for (String li : list) {
                //修改状态
                map1.put(li, "1");
            }
            String s = JSONObject.toJSONString(map1);
            log.info("更改座位状态：{}", s);
            movieDetailsService.changeSeatStram(s, perId);
            //将map转为String
//            String jsonResult = MapToStringUtil.mapToString(map1,",",":");
            //修改数据库座位状态


            //订单判断：超时支付作废订单，修改座位1->0；订单支付，修改座位1->2
            //t_perid 的 seat_stream
            new Timer().schedule(new TimerTask() {
                private int id = orderMessage.getId();

                @Override
                public void run() {
                    int id = orderMessage.getId();
                    log.info("执行下单与否的定时任务:{}", id);
                    TOrderMovie orderMovie = movieDetailsService.getOrderMovie(id); //根据id获取订单
                    int state = orderMovie
                            .getState();
                    if (state == 0) {
                        log.info("订单超时支付");
                        movieDetailsService.zuofeiOrderMovie(id);
                        movieDetailsService.zuofeiOrderTicket(id);
                        //修改座位状态 -- 恢复为0
                        String seats = movieDetailsService.getSetsByPerid(perId);
                        Map<String, String> map1 = (Map<String, String>) JSON.parse(seats);
                        for (String li : list) {
                            //修改状态
                            log.info("座位信息为：{}",li);
                            map1.put(li, "0");
                        }
                        String s = JSONObject.toJSONString(map1);
                        log.info("更改座位状态：{}", s);
                        movieDetailsService.changeSeatStram(s, perId);

                    }else if(state==1){
                        log.info("订单支付成功");
                        //修改座位状态 -- 改为2
                        String seats = movieDetailsService.getSetsByPerid(perId);
                        Map<String, String> map1 = (Map<String, String>) JSON.parse(seats);
                        for (String li : list) {
                            //修改状态
                            log.info("座位信息为：{}",li);
                            map1.put(li, "2");
                        }
                        String s = JSONObject.toJSONString(map1);
                        log.info("更改座位状态：{}", s);
                        movieDetailsService.changeSeatStram(s, perId);
                    }
                }
            }, 3 * 60 * 1000); //3分钟定时任务改订单状态

            map.put("totle", (i + ""));
            //hashOperations.put(out_trade_no1,out_trade_no,orderMessage);
            hashOperations.putAll(out_trade_no, map);
            Boolean bool = rLock.tryLock();
            if (bool) {
                rLock.unlock();
            }

            return Result.success();
        }
        return Result.fail(426, "验证码有误");
    }

    /**
     * 调用支付接口
     *
     * @return
     */

    public void payMoney(HttpServletResponse rep, @RequestParam("userTel") String userTel) {
        //获取电话
//        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//        HttpServletRequest request = servletRequestAttributes.getRequest();
//        String userTel1=request.getHeader("tel");
        BoundHashOperations boundListOperations = redisTemplate.boundHashOps("orderMessage_" + userTel);

        double totleMoney = Double.parseDouble((String) boundListOperations.get("totleMoney"));
        //totleMoney=Math.round(totleMoney*100)/100.0;
        BoundHashOperations boundListOperations1 = redisTemplate.boundHashOps("waiceng");
        String tradeNuo = (String) boundListOperations1.get("tradeNuo");
        //应支付的金额
        //计算手续费
        double allMoney = totleMoney;
        //订单号tradeNuo
        Result result = movieTicket.aliPay("用户购票订单,...", tradeNuo, "电影购票", allMoney);
        if (result.isSuccess()) {
            try {
                rep.setContentType("text/html;charset=utf-8");
                rep.getWriter().write(result.getData() + "");
                rep.getWriter().flush();
            } catch (IOException e) {
                e.printStackTrace();
            }

        } else {

        }
    }

    // TODO: 2020/12/10 展示用户拥有的优惠券
    public Result getDiscountByUserTel(@RequestParam(value = "tel") String tel, @RequestParam(value = "currpage", defaultValue = "1") int currpage, @RequestParam(value = "number", defaultValue = "10") int number) {
        log.info("分页展示优惠券所需参数{}{}{}", tel, currpage, number);
        Page<DiscountShow> page = new Page<>();
        page.setCurrent(currpage);
        page.setSize(number);
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("当前时间：" + simpleDateFormat.format(date));
        IPage<DiscountShow> discountShowIPage = movieDetailsService.getDiscountByUserTel(page, tel, simpleDateFormat.format(date));
        return Result.success(discountShowIPage);
    }

    /**
     * 通过输入的影片名模糊查询，再进行分页渲染
     *
     * @param movieName
     * @param currpage
     * @param number
     * @return
     */
    public Result getMovieByMovieName(@RequestParam(value = "movieName") String movieName, @RequestParam(value = "currpage", defaultValue = "1") int currpage, @RequestParam(value = "number", defaultValue = "10") int number) {
        log.info("分页模糊查询:{}{}{}", movieName, currpage, number);
        Page<MovieShow> page = new Page<>();
        page.setCurrent(currpage);
        page.setSize(number);
        IPage<MovieShow> movieShowIPage = movieDetailsService.getMovieByMovieName(page, movieName);
        return Result.success(movieShowIPage);
    }

    /**
     * 通过输入的影人名模糊查询，再进行分页渲染
     *
     * @param peopleName
     * @param currpage
     * @param number
     * @return
     */
    public Result getMovieByPeopleName(@RequestParam(value = "peopleName") String peopleName, @RequestParam(value = "currpage", defaultValue = "1") int currpage, @RequestParam(value = "number", defaultValue = "5") int number) {
        log.info("分页模糊查询:{}{}{}", peopleName, currpage, number);
        Page<PeopleShow> page = new Page<>();
        page.setCurrent(currpage);
        page.setSize(number);
        IPage<PeopleShow> movieShowIPage = movieDetailsService.getMovieByPeopleName(page, peopleName);
        return Result.success(movieShowIPage);
    }

    /**
     * 通过输入的影院名模糊查询，再进行分页渲染
     *
     * @param cinemaName
     * @param currpage
     * @param number
     * @return
     */
    public Result getMovieByCinemaName(@RequestParam(value = "cinemaName") String cinemaName, @RequestParam(value = "currpage", defaultValue = "1") int currpage, @RequestParam(value = "number", defaultValue = "5") int number) {
        log.info("分页模糊查询:{}{}{}", cinemaName, currpage, number);
        Page<CinemaShow> page = new Page<>();
        page.setCurrent(currpage);
        page.setSize(number);
        IPage<CinemaShow> movieShowIPage = movieDetailsService.getMovieByCinemaName(page, cinemaName);
        return Result.success(movieShowIPage);
    }
//    @ApiOperation(value = "根据电影类型，国家，年代进行动态筛选,并分页展示")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "movieType",value = "电影类型",dataType = "String"),
//            @ApiImplicitParam(name = "MovieAddress",value = "国家",dataType = "String"),
//            @ApiImplicitParam(name = "MovieTime",value = "年代",dataType = "String"),
//            @ApiImplicitParam(name = "currpage",value = "当前页码",dataType = "String"),
//            @ApiImplicitParam(name = "number",value = "每页展示数量",dataType = "String")
//    })

    /**
     * 根据电影类型，国家，年代进行动态筛选,并分页展示
     *
     * @param movieType
     * @param MovieTime
     * @param currpage
     * @param number
     * @return
     */
    public Result getMovieByTypeTime(@RequestParam(value = "movieType") String movieType, @RequestParam(value = "MovieTime") String MovieTime, @RequestParam(value = "currpage", defaultValue = "1") int currpage, @RequestParam(value = "number", defaultValue = "5") int number) {
        log.info("筛选电影参数{}{}{}{}{}", movieType, MovieTime, currpage, number);
        if (MovieTime.equals("全部")) {
            MovieTime = "";
        } else if (movieType.equals("全部")) {
            movieType = "";
        }
        Page<MovieShow> page = new Page<>();
        page.setCurrent(currpage);
        page.setSize(number);
        IPage<MovieShow> movieShowIPage = movieDetailsService.getMovieByTypeTime(page, movieType, MovieTime);
        return Result.success(movieShowIPage);
    }

}
